public class Solution766 {
    public boolean isToeplitzMatrix(int[][] matrix) {
        int m=matrix.length,n=matrix[0].length;
        for (int i=1-n;i<=m-1;i++){
            int t=matrix[Math.max(0,i)][Math.max(0,i)-i];
            for (int j=Math.max(0,i)+1;j<Math.min(m,n+i);j++){
                if (matrix[j][j-i]!=t){
                    return false;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new Solution766().isToeplitzMatrix(new int[][]{{1,2,3,4},{5,1,2,3},{9,5,1,2}}));
    }
}
